package cn.hn3l.agriculture.controllers;

import cn.hn3l.agriculture.services.interfaces.FileService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Wang Weiwei
 * @Since 16-10-22
 * @Describe
 */
@Controller
@RequestMapping("/file")
public class FileController {

    @Resource
    private FileService fileService;

    /**服务器图片输出地址*/
    @RequestMapping("/image/{id}")
    public void showJPEG(@PathVariable int id, HttpServletResponse response)
            throws IOException {
        byte[] imageBytes = fileService.getPictureBytesById(id);
        response.getOutputStream().write(imageBytes);
        response.getOutputStream().flush();
    }
}
